package com.sunsheng.modules.juc;

import java.util.concurrent.*;
//自定义线程池
public class ThreadPoolDemo1 {
    public static void main(String[] args) {
        ExecutorService service = new ThreadPoolExecutor(
                2, 10, 2L, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(3),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
        try {
            for (int i = 0; i < 20; i++) {
                service.execute(() -> {
                    System.out.println("当前是" + Thread.currentThread().getName() + "线程在处理");
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            service.shutdown();
        }
    }
}